package com.bupt.hotel.hvac.controller;

import com.bupt.hotel.hvac.model.vo.BillVO;
import com.bupt.hotel.hvac.service.CentralControllerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 退房服务控制器 - 统一接口标准
 * 提供退房相关功能
 */
@Slf4j
@RestController
@RequestMapping("/api/checkout")
public class CheckOutController {

    private final CentralControllerService centralControllerService;

    public CheckOutController(CentralControllerService centralControllerService) {
        this.centralControllerService = centralControllerService;
    }

    /**
     * 办理退房
     * GET /api/checkout/{roomId}
     */
    @GetMapping("/{roomId}")
    public Map<String, Object> checkout(@PathVariable String roomId) {
        log.info("办理退房 - 房间: {}", roomId);
        
        try {
            BillVO bill = centralControllerService.checkout(roomId);
            
            Map<String, Object> result = new HashMap<>();
            result.put("success", true);
            result.put("message", "退房办理成功");
            result.put("bill", bill);
            
            return result;
        } catch (Exception e) {
            log.error("办理退房失败: {}", e.getMessage());
            Map<String, Object> result = new HashMap<>();
            result.put("success", false);
            result.put("error", e.getMessage());
            return result;
        }
    }
}
